package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.entity.JcContactcompany;
import com.xdf.xzymanagementsystem.entity.Payment;
import com.xdf.xzymanagementsystem.entity.ResponseResult;
import com.xdf.xzymanagementsystem.enums.MenuConstant;
import com.xdf.xzymanagementsystem.enums.OperateConstant;
import com.xdf.xzymanagementsystem.enums.ResponseEnum;
import com.xdf.xzymanagementsystem.enums.SeparatorConstant;
import com.xdf.xzymanagementsystem.service.PaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 注意要有依赖：
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger2</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger-ui</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 * 同时入口类头上使用注解：@EnableSwagger2
 * @Description : 控制层，代码生成器自动生成
 * @Author : chanchaw
 * @Date : 2025-3-22 10:27:04
 */
@Api(tags = "应付款")
@CrossOrigin
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentService service;
    //=================以上是自动生成的代码，自定义代码请写在下面==================

    /**
     * 选择新增 - 白坯
     * @param record
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "选择新增")
    @RequiresPermissions(MenuConstant.MENU301 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelectiveSupplier", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelectiveSupplier(@RequestBody Payment record) throws Exception {
        record.setCategory(0);
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 选择新增 - 染厂
     * @param record
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "选择新增")
    @RequiresPermissions(MenuConstant.MENU302 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelectiveDyeing", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelectiveDyeing(@RequestBody Payment record) throws Exception {
        record.setCategory(1);
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 选择新增 - 深加工
     * @param record
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "选择新增")
    @RequiresPermissions(MenuConstant.MENU302 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelectiveDeep", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelectiveDeep(@RequestBody Payment record) throws Exception {
        record.setCategory(2);
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 选择新增 - 成品
     * @param record
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "选择新增")
    @RequiresPermissions(MenuConstant.MENU302 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelectiveProduct", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelectiveProduct(@RequestBody Payment record) throws Exception {
        record.setCategory(4);
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 选择修改
     * @param record
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "选择修改", httpMethod = "PUT", notes = "选择修改")
    @RequiresPermissions(MenuConstant.MENU301 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    @RequestMapping(value = "/updateSelective", method = RequestMethod.POST)
    public ResponseResult<Void> updateSelective(@RequestBody Payment record) throws Exception {
        service.updateByPrimaryKeySelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 根据主键查询
     * @param id
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "根据主键查询", httpMethod = "GET", notes = "根据主键查询")
    @RequiresPermissions(MenuConstant.MENU301 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @RequestMapping(value = "/queryByPk/{id}", method = RequestMethod.GET)
    public Payment selectByPrimaryKey(@PathVariable("id") Integer id) throws Exception {
        if (id == null) return null;
        return service.selectByPrimaryKey(id);
    }

    /**
     * 根据主键删除
     * @param id
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "根据主键删除", httpMethod = "GET", notes = "根据主键删除")
    @RequiresPermissions(MenuConstant.MENU301 + SeparatorConstant.SEPARATOR + OperateConstant.DELETE)
    @RequestMapping(value = "/deleteByPrimaryKey/{id}", method = RequestMethod.GET)
    public ResponseResult<Void> deleteByPrimaryKey(@PathVariable("id") Integer id) throws Exception {
        if (id == null) return null;
        service.deleteByPrimaryKey(id);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 白坯应付款
     *
     * @param sdate         起始日期
     * @param edate           终止日期
     * @param client  坯布商名称
     * @param value         是否汇总
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "白坯应付款", httpMethod = "GET/POST", notes = "报表查询")
    @RequiresPermissions(MenuConstant.MENU301 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @RequestMapping(value = "/selectGreyMeet")
    public List<Map<String, Object>> selectGreyMeet(
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date sdate,
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date edate,
            String client,
            Integer value) throws Exception {
        return service.selectGreyMeet(sdate, edate, client, value);
    }

    /**
     * 染厂应付款
     *
     * @param sdate         起始日期
     * @param edate           终止日期
     * @param client  坯布商名称
     * @param value         是否汇总
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "染厂应付款", httpMethod = "GET/POST", notes = "报表查询")
    @RequiresPermissions(MenuConstant.MENU302 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @RequestMapping(value = "/selectDyeingMeet")
    public List<Map<String, Object>> selectDyeingMeet(
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date sdate,
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date edate,
            String client,
            Integer value) throws Exception {
        return service.selectDyeingMeet(sdate, edate, client, value);
    }

    /**
     * 深加工应付款
     *
     * @param sdate         起始日期
     * @param edate           终止日期
     * @param client  坯布商名称
     * @param value         是否汇总
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "深加工应付款", httpMethod = "GET/POST", notes = "报表查询")
    @RequiresPermissions(MenuConstant.MENU303 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @RequestMapping(value = "/selectDeepMeet")
    public List<Map<String, Object>> selectDeepMeet(
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date sdate,
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date edate,
            String client,
            Integer value) throws Exception {
        return service.selectDeepMeet(sdate, edate, client, value);
    }

    /**
     * 成品应收款
     *
     * @param sdate         起始日期
     * @param edate           终止日期
     * @param client  坯布商名称
     * @param value         是否汇总
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "成品应收款", httpMethod = "GET/POST", notes = "报表查询")
    @RequiresPermissions(MenuConstant.MENU304 + SeparatorConstant.SEPARATOR + OperateConstant.SHOW)
    @RequestMapping(value = "/selectClientCollect")
    public List<Map<String, Object>> selectClientCollect(
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date sdate,
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date edate,
            String client,
            Integer value) throws Exception {
        return service.selectClientCollect(sdate, edate, client, value);
    }
}